package com.fagejiang.springbootkafka.controller;

import org.apache.tomcat.util.http.ConcurrentDateFormat;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;

/**
 * TODO
 *
 * @author 发哥讲Java
 * @version 1.0
 * @date 2021-04-28 11:20
 */
@RestController
@RequestMapping("/kafka")
public class KafkaController {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/send/{num}")
    public String sendNum(@PathVariable("num") Integer num) {
        for (int i = 0; i < num; i++) {
            String format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
            String uuid = UUID.randomUUID().toString();
             String value = format + " ==> " + uuid;
            System.out.println("value = " + value);
            kafkaTemplate.send("springboot-kafka-topic", value);
        }
        return "success";
    }

    public static void main(String[] args) {
        System.out.println(new Date());
        System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
        System.out.println(UUID.randomUUID().toString());
    }
}
